/
export_UI.py
115 lines (97 loc) · 4.03 KB
/
export_UI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import subprocess
import sys
import pygame
import UI.Components.EzButton
import UI.Components.EzText
import UI.Components.EzTextField
import UI.Components.EzToggle
from Core import EZ
from UI.Components.EzButton import check_ez_button_event
# parameters
json_file = "/Resources/Components/export_app_components.json"
class ExportUI:
def __init__(self, app):
self.app = app
self.ez_texts: list[UI.Components.EzText.EzText] = UI.Components.EzText.loader(
self.app.working_directory + json_file
)
self.ez_buttons: list[UI.Components.EzButton.EzButton] = UI.Components.EzButton.loader(
self.app.working_directory + json_file
)
self.ez_textFields: list[
UI.Components.EzTextField.EzTextField
] = UI.Components.EzTextField.loader(self.app.working_directory + json_file)
self.params: list[float] = [
self.ez_textFields[0].input_value
]
def draw(self):
# draw the texts
for text in self.ez_texts:
text.create_text()
# draw the buttons
for button in self.ez_buttons:
button.create_button()
# draw the text fields
for textField in self.ez_textFields:
textField.create_text_field()
def update(self):
EZ.update()
def run(self):
self.draw()
self.update()
def check_events(self):
event = EZ.get_event()
mouse_x, mouse_y = EZ.mouse_coordinates()
if event == "EXIT" or event == "KEY_DOWN" and EZ.key() == "ESCAPE":
EZ.destroy_window()
sys.exit()
# check if the user clicks the mouse
if event == "MOUSE_LEFT_BUTTON_DOWN":
# check if the user clicked a button or toggle
checked_ez_button = check_ez_button_event(self.ez_buttons, mouse_x, mouse_y)
# button check
if checked_ez_button is not None:
# help button -> open help.html
if checked_ez_button.name == "btnOpenFolder":
try:
os.startfile(os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/"))
except Exception as e:
print("Error:", e)
try:
subprocess.Popen(
["xdg-open", os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/")])
except Exception as e:
print("Error:", e)
if checked_ez_button.name == "btnExport":
with open(os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/count.txt"), "r") as f:
index = int(f.read())
f.close()
with open(os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/count.txt"), "w") as f:
f.write(str(index + 1))
f.close()
self.app.fractal.save_image(
(os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/" + f"image{index}.png")),
self.params[0])
if checked_ez_button.name == "btnReturn":
self.app.run()
checked_ez_button.create_button()
if event == "KEY_DOWN":
key = EZ.key()
# text field check
for textField in self.ez_textFields:
if textField.check_hover(mouse_x, mouse_y):
textField.on_hover(key, self)
textField.create_text_field()
# check hover and change cursor
if any(
button.check_hover(mouse_x, mouse_y) for button in self.ez_buttons
):
EZ.change_cursor(pygame.SYSTEM_CURSOR_HAND)
elif any(
textField.check_hover(mouse_x, mouse_y) for textField in self.ez_textFields
):
EZ.change_cursor(pygame.SYSTEM_CURSOR_IBEAM)
else:
EZ.change_cursor(pygame.SYSTEM_CURSOR_ARROW)
self.update()